package logic

import (
	"Junior_two/subject/cart/cartrpc/utils"
	"context"
	"fmt"
	"net/http"

	"Junior_two/subject/cart/cartrpc/internal/svc"
	"Junior_two/subject/cart/cartrpc/pb/cartRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteLogic {
	return &DeleteLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeleteLogic) Delete(in *cartRpc.DeRequest) (*cartRpc.Response, error) {
	// todo: add your logic here and delete this line
	HKeY := "cart:user_id" + fmt.Sprintf("%d", in.UserId)
	if !utils.RedisDel(HKeY, in.GoodId) {
		return &cartRpc.Response{
			Msg:  "删除失败",
			Code: http.StatusBadRequest,
		}, nil
	}
	return &cartRpc.Response{
		Msg:  "删除成功",
		Code: http.StatusOK,
	}, nil
}
